import Http, { HttpParamsProps, ReqProps } from "@/common/http";
import { BaseEntitys } from "@/common/httptypes";
import { SelectDataArray } from "@/components/ant-ext/HStaticSelect";
import { type } from "os";

//后期需整改数据-没用的删掉--selectById
export type SysRoleEntity = {
    id: string
    roleName: string
    deptName?: string
    deptId?:string
} & BaseEntitys


// 角色获取对应菜单的id，后期需要整改--selectRoleMenu
export type SelectRoleMenu = {
    allChildren?: boolean
    id?: string
    roleId?: string
    menuId?: string
} & BaseEntitys


// 处理角色对应菜单数据接口，目的只拿到key值['string']
// 转化函数
export function SelectedMenuArr(arr: any, data: any) {
    for (let i in data) {
      let item = data[i];
      if (item.allChildren) {
        arr.push(item.menuId);
      }
    }
    return arr
  }


class SysRole {
    RowKey = "id"
    EDIT = "roleManagementEdit"
    ADD = "roleManagementAdd"
    DEL = "roleManagementDelete"
    ROLE_MENU = "roleManagementMenu"
    MAPPING = { roleManagementEdit: "编辑角色", roleManagementAdd: "新增角色" }
    ROLE_MENU_MAPPING = { roleManagementMenu: "分配权限" }


    selectTablePage(props: HttpParamsProps): Promise<Response> {
        return Http.get("/role/select", props)
    }

    // 分配权限
    selectRoleMenu(props: ReqProps<SelectRoleMenu>) {
        Http.doGet("/menu/roleMenu/getByRoleId", props)
    }

    //后期需要修改接受接口 只传{roleId:'',selected:['string']}
    doEditRoleMenu(props: ReqProps<void>) {
        Http.doPost("/roleDept/saveBatch", props)
    }


    selectById(props: ReqProps<SysRoleEntity>) {
        Http.doGet("/role/getById", props)
    }

    doEdit(props: ReqProps<void>) {
        Http.doPost("/role/edit", props)
    }
    doSave(props: ReqProps<void>) {
        Http.doPost("/role/save", props)
    }

    delete(props: ReqProps<void>) {
        Http.doDelete("/role/deleteById", props)
    }






    selectList(props: ReqProps<SelectDataArray>) {
        Http.doGet("/api/role/list", props)
    }


}

// eslint-disable-next-line import/no-anonymous-default-export
export default new SysRole()